/**
 * Created by IAN on 2016/10/14.
 */
$(function () {
    //select 加载
    var meetSel = $.Params.create();
    meetSel.ajax("get", getMeetIP() + "meet", function (data) {
        var html = "<option value='0'>请选择会议</option>";
        if(data.count > 0){
            $.each(data.rows,function(i,val){
                html+="<option value = '"+val.id+"'>"+val.meetTitle+"</option>";
            })
        }
       $("#meetTitle").html(html);
    })


    var sel = $.Params.create();
    sel.addParams("page", 0);
    sel.addParams("rows", rows);
    getData();

    //查询
    $("#searchBtn").on("click", function () {
        var meetId = $("#meetTitle").val();
        var title = $("#title").val();
        if(meetId != "0"){
            sel.addParams("meetId", meetId);
        }else{
            sel.addParams("meetId", undefined);
        }
        if (title != "") {
            sel.addParams("buildTitle", title);
        } else {
            sel.addParams("buildTitle", undefined);
        }
        getData();
    })

    //判断checkbox状态
    $("#selAll").on("click", function () {
        if (!$(this).attr("checked")) {
            $("input[type=checkbox]").attr("checked", "checked")
        } else {
            $("input[type=checkbox]").removeAttr("checked");
        }
    })

    //添加事件
    $('#addDataBtn').on("click", function () {
        window.location.href = "buildAdd.html";
    });

    //删除事件
    $('#delBtn').on("click", function () {
        var params = getCheckData();
        if (params != "") {
            if (confirm("确定要删除吗！")) {
                var del = $.Params.create();
                //del.addParams("params", params)
                del.ajax("delete", getMeetIP() + "build?params=" + params, function (data) {
                    
                        alert("删除成功！");
                        getData();
                    
                })
            }
        } else {
            alert("请至少选中一项");
        }
    });

    //获取数据
    function getData() {
        getPageData("get", sel, getMeetIP() + "build", function (data) {
                var html = "";
                if (data.count > 0) {
                    $.each(data.rows, function (i, val) {
                        html += "<tr role='row'' class='even'>" +
                            "<td><input eid='" + val.id + "' onclick='getCheck(this)' type='checkbox' class='classOption'></td>" +
                            "<td>" + val.Meet.meetTitle + "</td>" +
                            "<td>" + val.buildTitle + "</td>" +
                            "<td>" + val.code + "</td>" +
                            "<td><button type='button' class='btn btn-primary'  onclick='updateInfo(\"" + val.id + "\")'>修改</button></td>" +
                            "</tr>";
                    });

                } else {
                    html = "<tr><td>暂无数据</td></tr>"
                }
                $("#listContainer").html(html);
        })
    }
    updateInfo = function (eid) {
        window.location.href = "buildUpdate.html?eid=" + eid;
    }
});

